package com.cloudpolice.door.service.Impl;

import com.cloudpolice.door.dao.FaceLogMapper;
import com.cloudpolice.door.dto.FaceLogDTO;
import com.cloudpolice.door.model.FaceLogRecordMainModel;
import com.cloudpolice.door.model.InPutParam.FaceLogInsertInParam;
import com.cloudpolice.door.model.InPutParam.FaceLogSelectInParam;
import com.cloudpolice.door.model.InPutParam.FaceLogSubInsertInParam;
import com.cloudpolice.door.service.FaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：梁昊，后端工程师：flyman5，前端工程师：孙耀
 * @create 2020-02-28 12:17
 * @function
 * @editLog
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class FaceLogServiceImpl implements FaceLogService {
    @Autowired
    FaceLogMapper faceLogMapper;

    /**
     * 得到门禁机抓拍记录根据
     *
     * @param personId 人员ID（居民，物业人员，警务人员)
     * @return 抓拍记录
     */
    @Override
    public List<FaceLogRecordMainModel> SelectFaceLogByPersonId(String personId) {
        return faceLogMapper.SelectFaceLogByPersonId(personId);
    }

    /**
     * 更新门禁记录关联信息（MQ接收端）
     *
     * @param faceLogInsertInParam com.cloudpolice.door.model.InPutParam.FaceLogInsertInParam
     * @return 影响条数
     */
    @Override
    public int updateFaceLogById (FaceLogInsertInParam faceLogInsertInParam) {
        return faceLogMapper.updateFaceLogById(faceLogInsertInParam);
    }

    /**
     * 增加门禁记录（MQ接收端）
     *
     * @param faceLogInsertInParam com.cloudpolice.door.model.InPutParam.FaceLogBaseInsertInParam
     * @return 影响条数
     */
    @Override
    public int insertAllFaceLog(FaceLogInsertInParam faceLogInsertInParam, List<FaceLogSubInsertInParam> faceLogSubInsertInParams) {
        int count = faceLogMapper.insertAllFaceLog(faceLogInsertInParam);
        if (count > 0) {
            if (faceLogSubInsertInParams != null) {
                for (FaceLogSubInsertInParam faceLogSubInsertInParam :
                        faceLogSubInsertInParams) {
                    count += faceLogMapper.insertAllFaceSubLog(faceLogSubInsertInParam);
                }
            }
//            FaceLogInsertInParam faceLogInsertInParamNew = new FaceLogInsertInParam();
//            faceLogInsertInParamNew.setId(faceLogInsertInParam.getId());
//            faceLogInsertInParamNew.setPersonName("PersonName1");
//            faceLogInsertInParamNew.setAccessName("AccessName1");
//            faceLogInsertInParamNew.setBlackTag("BlackTag");
//            faceLogInsertInParamNew.setBlackType("BlackType");
//            faceLogInsertInParamNew.setBuildId("BuildId");
//            faceLogInsertInParamNew.setCommunityId("ComId");
//            faceLogInsertInParamNew.setCommunityName("ComName");
//            faceLogInsertInParamNew.setEquipmentName("EquipName");
//            faceLogInsertInParamNew.setEquipmentType(0);
//            faceLogInsertInParamNew.setLatitude((float) 23.3245324);
//            faceLogInsertInParamNew.setLongitude((float) 3435.4564);
//            faceLogInsertInParamNew.setMobile("13972342314");
//            faceLogInsertInParamNew.setPeriodId("PeroidId");
//            faceLogInsertInParamNew.setPeriodName("PeroidName");
//            faceLogInsertInParamNew.setUnitId("UnitId");
//            faceLogInsertInParamNew.setUnitName("UnitName");
//            faceLogInsertInParamNew.setSex("0");
//
//            count += faceLogMapper.updateFaceLogById(faceLogInsertInParamNew);
        }
        return count;
    }

    /**
     * 根据ID查询开门记录
     *
     * @param id 主键
     * @return 开门记录
     */
    @Override
    public FaceLogInsertInParam selectFaceLogById(String id) {
        return faceLogMapper.selectFaceLogById(id);
    }

    /**
     * 根据相关参数查询开门记录
     *
     * @param faceLogSelectInParam 根据相关参数查询开门记录
     * @return 根据相关参数查询开门记录
     */
    @Override
    public List<FaceLogDTO> selectFaceLogsByParam(FaceLogSelectInParam faceLogSelectInParam) {
        return faceLogMapper.selectFaceLogsByParam(faceLogSelectInParam);
    }
}
